import { default as http } from "@/http";
import {
  ApplicableStageEnum,
  ApprovalStatusEnum,
  ConnectedDomainEnum,
  IndicatorTypeEnum,
  PortfolioEnum,
  ProjectTypeEnum,
  ScaleEnum,
} from "@/utils";
export * from "./file";
export * from "./user";
export * from "./project";
export * from "./indicator";
export type ProjectItem = {
  id?: string;
  projectName: string;
  desc?: string;
  createTime: number;
  status: ApprovalStatusEnum;
} & GetProjectRequest &
  Record<string, any>;
// import { findProjectDetail, indicatorSystemList } from "./mock";
type GetProjectRequest = {
  projectScale?: ScaleEnum; // 项目规模
  projectType?: ProjectTypeEnum; // 项目类型
  portfolio?: PortfolioEnum; // 资产组合
  applicableStage?: ApplicableStageEnum; // 适用阶段
  connectedDomain?: ConnectedDomainEnum; // 关联领域
  name?: string; // 模糊搜索项目名称
  current?: number;
  pageSize?: number;
} & Record<string, any>;
/**
 * @description: 获取项目列表
 */
// export const getProjectList = (data: GetProjectRequest) => {
//   return http.postReq({ url: "/project/getList", data }).then(() => {
//     const { current = 1, pageSize = 20, name, ...rest } = data;
//     const list = projectList.filter((item: ProjectItem) => {
//       // 该项找不到筛选项不是全部且不等于筛选项值的属性则返回
//       return (
//         (!name ||
//           item.projectName.toLowerCase().includes(name.toLowerCase())) &&
//         Object.keys(rest).every((key) => !data[key] || item[key] === data[key])
//       );
//     });
//     return {
//       list: list.slice(pageSize * (current - 1), pageSize * current),
//       total: list.length,
//     };
//   });
// };
/**
 * @description: 获取项目详情
 */
// export const getProjectDetail = (id: string) => {
//   return http.getReq({ url: "/project/get", params: { id } }).then(() => {
//     return findProjectDetail(id);
//   });
// };
/**
 * @description: 保存项目基本信息
 */
export const saveProjectBasicInfo = (data: any) => {
  return http.postReq({ url: "/project/saveBasicInfo", data });
};
export type IndicatorItem = {
  id: string;
  indicatorName: string;
  indicatorType?: IndicatorTypeEnum;
  score: number;
  actual?: number;
  status?: IndicatorTypeEnum;
  fillConfig?: FormItem[];
  fillData?: Record<string, any>;
  children?: IndicatorItem[];
};
// export type IndicatorSystemItem = {
//   value: string;
//   label: string;
//   total: number;
//   indicators: IndicatorItem[];
// };
/**
 * @description: 获取指标体系选项
 */
// export const getIndicatorSystemOptions = (): Promise<IndicatorSystemItem[]> => {
//   return http.getReq({ url: "/project/getIndicatorSystemOptions" }).then(() => {
//     return indicatorSystemList;
//   });
// };
/**
 * @description: 保存项目基本信息
 */
export const saveIndicators = (data: any) => {
  return http.postReq({ url: "/project/saveIndicators", data });
};
/**
 * @description: 获取用户列表
 */
// export const getUserList = (params: any) => {
//   return http.getReq({ url: "/manage/user/list", params }).then(() => {
//     const { applyPurpose, status, pageSize, current, name } = params;
//     const list = userList.filter(
//       (item) =>
//         (applyPurpose === undefined ||
//           item.applyPurpose.find((aItem: number) =>
//             (applyPurpose as number[]).includes(aItem)
//           )) &&
//         (status === undefined || item.status === status) &&
//         (name === undefined ||
//           item.name.toLowerCase().includes(name.toLowerCase()))
//     );
//     return {
//       list: list.slice(pageSize * (current - 1), pageSize * current),
//       total: list.length,
//     };
//   });
// };
export type Indicator3Item = {
  value: string;
  label: string;
  indicator1Name: string;
  indicator1Id: string;
  indicator2Name: string;
  indicator2Id: string;
  indicator3Name: string;
  indicator3Id: string;
};
/**
 * @description: 替换指标，搜索指标
 */
// export const getIndicators = (data: any): Promise<Indicator3Item[]> => {
//   return http.getReq({ url: "/project/getIndicators" }).then(() => {
//     const { name } = data;
//     return indicatorSystemList.reduce<Indicator3Item[]>((sum, item) => {
//       const { value, label } = item;
//       item.indicators.forEach((indicator1) => {
//         const { indicatorName: indicator1Name, id: indicator1Id } = indicator1;
//         indicator1.children?.forEach((indicator2) => {
//           const { indicatorName: indicator2Name, id: indicator2Id } =
//             indicator2;
//           indicator2.children?.forEach((indicator3) => {
//             const { indicatorName: indicator3Name, id: indicator3Id } =
//               indicator3;
//             if (
//               !name ||
//               indicator1Name.toLowerCase().includes(name.toLowerCase())
//             ) {
//               sum.push({
//                 value,
//                 label,
//                 indicator1Name,
//                 indicator1Id,
//                 indicator2Name,
//                 indicator2Id,
//                 indicator3Name,
//                 indicator3Id,
//               });
//             }
//           });
//         });
//       });
//       return sum;
//     }, []);
//   });
// };
